<template>
<view class="container">
    <form class="backTextContainer" @submit="getValues">
      <view class="textAreaContainer">
        <view>物流公司</view>
        <input class="textAreaContainer_textArea" maxlength="10" @input="getwuliuCom" value name="wuliuCom"></input>
      </view>
      <view class="textAreaContainer">
        <view>物流单号</view>
        <input class="textAreaContainer_textArea" maxlength="20" @input="getwuliuNo" value name="wuliuNo"></input>
      </view>
      <view class="textAreaContainer">
        <view>运费</view>
        <input type="number" maxlength="6" class="textAreaContainer_textArea2" @input="getwuliuAmount" value name="wuliuAmount"></input>
      </view>

      <button :style="'background:' + setting.platformSetting.defaultColor" formType="submit">确认退货单</button>
    </form>  
</view>
</template>

<script>

export default {
  data() {
    return {
      setting: null,
      shopBackAmountId: '',
      loginUser: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    if (!options.shopBackAmountId) {
      getApp().globalData.loadFail();
    }

    this.setData({
      shopBackAmountId: options.shopBackAmountId
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
    this.setData({
      loginUser: getApp().globalData.loginUser
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  methods: {
    getwuliuNo(e) {
      //console.log(e.detail.value)
      this.wuliuNo = e.detail.value;
    },

    getwuliuCom(e) {
      this.wuliuCom = e.detail.value;
    },

    getwuliuAmount(e) {
      this.wuliuAmount = e.detail.value;
    },

    getValues(e) {
      // console.log(e.detail.value)
      let postParam = {};
      postParam.wuliuCom = e.detail.value.wuliuCom;

      if (!postParam.wuliuCom) {
        postParam.wuliuCom = this.wuliuCom;
      }

      postParam.wuliuNo = e.detail.value.wuliuNo;

      if (!postParam.wuliuNo) {
        postParam.wuliuNo = this.wuliuNo;
      }

      postParam.wuliuAmount = e.detail.value.wuliuAmount;

      if (!postParam.wuliuAmount) {
        postParam.wuliuAmount = this.wuliuAmount;
      }

      if (postParam.wuliuAmount) {
        if (isNaN(postParam.wuliuAmount)) {
          getApp().globalData.echoErr('运费请填写数字');
          return;
        }
      }

      postParam.shopBackAmountId = this.shopBackAmountId;
      console.log(postParam);

      if (!postParam.wuliuCom) {
        getApp().globalData.echoErr('请填写物流公司');
      } else if (!postParam.wuliuNo) {
        getApp().globalData.echoErr('请填写物流单号');
      } else if (!postParam.wuliuAmount) {
        getApp().globalData.echoErr('请填写运费');
      } else {
        this.sureBackItem(postParam);
      }
    },

    // 上传
    sureBackItem: function (postParam) {
      var that = this;
      wx.showModal({
        title: '提示',
        content: '确认以上填写信息正确，若没有可填无',
        success: function (res) {
          if (res.confirm) {
            var customIndex = getApp().globalData.AddClientUrl("/send_back_order_item_wuliu.html", postParam, 'post');
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: getApp().globalData.headerPost,
              method: 'POST',
              success: function (res) {
                console.log(res.data);

                if (res.data.errcode == '0') {
                  wx.showToast({
                    title: '发送成功',
                    icon: 'success',
                    duration: 2000
                  });
                  setTimeout(function () {
                    wx.navigateBack();
                  }, 2000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/images/icons/tip.png',
                    duration: 2000
                  });
                }
              },
              fail: function (res) {}
            });
          } else if (res.cancel) {}
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>